<?
use \PFT\Db;
use \PFT\PriceGroup;

// if(!$_SESSION['memberID']) {
// 	header("Location:dlogin_n.html");
// }
include("common/autoload.php");
var_dump(PriceGroup::addNewGroup(3386, '测试分组2'));die;
// PriceGroup::joinGroup(1,3383); 
die;

include("common/header.html");
include("common/left.html");
include("../_made/le.cfg.php");
include("common/func.inc.php");

include('module/common/Db.class.php');



$soap_client = new SoapClient(null, array(
	"location" => "http://localhost/open/openService/pft_insideMX.php", 
	"uri" => "www.16u.com?ac_16u=".$GLOBALS['_ac']."|pw_16u=".$GLOBALS['_pw']."|auth_16u=true")
);

$sid = $_SESSION['sid'];
$did = intval($_REQUEST["did"]);

//获取分销商名称
$member_info = Db::fetch(
	"SELECT dname FROM pft_member WHERE id=:id LIMIT 1",
	 array(':id' => $did)
);
$dname = $member_info['dname'];

$price_mapping = array();
$priceset = Db::fetchAll(
	"SELECT tid,dprice FROM uu_priceset WHERE pid=:did AND (aid=0 or aid=:sid) ORDER BY aid ASC",
	array(':did' => $did, ':sid' => $sid)
);
foreach ($priceset as $item) {
	$price_mapping[$item['tid']] = $item['dprice'];
}

//所能购买的供应商产品
$pids = Db::fetch(
	"SELECT pids FROM pft_product_sale_list WHERE fid=:did AND aid=:sid LIMIT 1",
	array(':did' => $did, ':sid' => $sid)
);
$allow_pids = $pids['pids'] == 'A' ? 'A' : explode(',', $pids['pids']);

//获取殴模板id
$tpl = Db::fetch(
	"SELECT tplid FROM uu_fx_tpl_cs WHERE fxid=:did LIMIT 1",
	array(':did' => $did)
);
$tplid = $tpl['tplid'];	//此变量在模板中有使用

$where = '';
if (isset($_REQUEST['prodname']) && !empty($_REQUEST['prodname'])) {
	$where = "and p_name like '%" . safetxt($_REQUEST['prodname']) . "%'";
}
$result = Db::fetchAll(
	"SELECT p.id,p.apply_did,p_name,e.lvl,e.sid 
	FROM uu_products p LEFT JOIN pft_p_apply_evolute e 
	ON p.id=pid and e.fid=:sid
	WHERE (p.p_status=0 OR p.p_status=3) AND p.apply_limit=1 AND (active=1 OR p.apply_did=:sid) $where",
	array(':sid' => $sid)
);

$prod = array();
foreach ($result as $item) {
	if ($item['apply_did'] != $sid) {
		continue;
	}
	$pri = $soap_client->get_Dynamic_Price_Merge($item['id'], date("Y-m-d"), 1);
    if ($pri == -1) {
		$pri = $soap_client->get_Dynamic_Price_Merge($item['id'], date("Y-m-d"), 2);
	}
	if ($pri == -1) {
		continue;
	} else {
		$item['fp'] = $pri / 100;
	}
	if (($allow_pids == "A" && $item['apply_did'] == $sid) || in_array($item['id'],$allow_pids)) {
		$item['pri'] = $price_mapping[$item['id']] / 100;
		$item['disabled'] = "";
		$item['checked'] = "checked";
	} else {
		$item['pri'] = $item['checked'] = "";
		$item['disabled'] = "disabled";
	}
	$prod[$item['id']]=$item;
}

include("tpl/priceset_new.html");
include("common/footer.html");?>